package cn.yuanqiao.web.controller.manage;

import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.core.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.core.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;
import cn.yuanqiao.manage.domain.YqdaCodelistModel;
import cn.yuanqiao.manage.service.IYqdaCodelistModelService;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * codelistController
 * 
 * @author yuanqiao
 * @date 2023-06-15
 */
@RestController
@RequestMapping("/manage/codelist")
public class YqdaCodelistModelController extends BaseController
{
    @Autowired
    private IYqdaCodelistModelService yqdaCodelistModelService;

    /**
     * 查询codelist列表
     */
    //@PreAuthorize("@ss.hasPermi('manage:codelist:list")
    @Log(title = "获取档号明细模板列表", businessType = BusinessType.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(YqdaCodelistModel yqdaCodelistModel)
    {
        startPage();
        List<YqdaCodelistModel> list = yqdaCodelistModelService.selectYqdaCodelistModelList(yqdaCodelistModel);
        return getDataTable(list);
    }

    /**
     * 导出codelist列表
     */
    //@PreAuthorize("@ss.hasPermi('manage:codelist:export")
    @Log(title = "导出档号明细模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YqdaCodelistModel yqdaCodelistModel)
    {
        List<YqdaCodelistModel> list = yqdaCodelistModelService.selectYqdaCodelistModelList(yqdaCodelistModel);
        ExcelUtil<YqdaCodelistModel> util = new ExcelUtil<YqdaCodelistModel>(YqdaCodelistModel.class);
        util.exportExcel(response, list, "codelist数据");
    }

    /**
     * 获取codelist详细信息
     */
    //@PreAuthorize("@ss.hasPermi('manage:codelist:query")
    @Log(title = "获取档号明细模板详细信息", businessType = BusinessType.SELECT)
    @GetMapping(value = "/{Id}")
    public AjaxResult getInfo(@PathVariable("Id") Long Id)
    {
        return success(yqdaCodelistModelService.selectYqdaCodelistModelById(Id));
    }

    /**
     * 新增codelist
     */
    //@PreAuthorize("@ss.hasPermi('manage:codelist:add")
    @Log(title = "新增档号明细模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JSONObject json)
    {
        return toAjax(yqdaCodelistModelService.insertYqdaCodelistModel(json));
    }

    /**
     * 修改codelist
     */
    //@PreAuthorize("@ss.hasPermi('manage:codelist:edit")
    @Log(title = "修改档号明细模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JSONObject json)
    {
        return toAjax(yqdaCodelistModelService.updateYqdaCodelistModel(json));
    }

    /**
     * 删除codelist
     */
    //@PreAuthorize("@ss.hasPermi('manage:codelist:remove")
    @Log(title = "删除档号明细模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{Ids}")
    public AjaxResult remove(@PathVariable Long[] Ids)
    {
        return toAjax(yqdaCodelistModelService.deleteYqdaCodelistModelByIds(Ids));
    }

    /**
     *
     * @param archivalcodeRuleId
     * @return
     */
    //@PreAuthorize("@ss.hasPermi('manage:codelist:query")
    @Log(title = "获取档号明细模板回显", businessType = BusinessType.SELECT)
    @GetMapping(value = "/getdetail/{type}/{archivalcodeRuleId}")
    public AjaxResult getdetail(@PathVariable("type") String type, @PathVariable("archivalcodeRuleId") Long archivalcodeRuleId)
    {
        return success(yqdaCodelistModelService.getdetail(type,archivalcodeRuleId));
    }
}
